import { createRouter, createWebHashHistory } from "vue-router";
import store from '@/store'
const  router= createRouter({
  history: createWebHashHistory(),
  routes: [
    {
      path: "/",
      redirect: {
        path: "/login",
      },
      component: () => import("@/view/index.vue") ,
      children: [
        { path: "/index/index", component: () => import("@/view/main.vue") },
        {
          path: "/image/index",
          component: () => import("@/view/image/image.vue"),
        },
        {
          path: "/shop/goods/list",
          component: () => import("@/view/shop_goods_list/shop_goods_list.vue"),
        },
        {
          path: "/shop/category/list",
          component: () => import("@/view/shop_goods_list/category_list.vue"),
        },
        {
          path:'/shop/sku/list',
          component: () => import("@/view/shop_goods_list/sku_list.vue"),
        },
        {
          path:'/shop/type/list',
          component: () => import("@/view/shop_goods_list/type_list.vue"),
        },
        {
          path:'/shop/comment/list',
          component: () => import("@/view/shop_goods_list/comment_list.vue"),
        },
        {
          path:'/order/order/list',
          component: () => import("@/view/ord/orderlist.vue"),
        },
        {
          path:'/order/invoice/list',
          component: () => import("@/view/ord/invoicelist.vue"),
        },
        {
          path:'/order/after-sale/list',
          component: () => import("@/view/ord/after-salelist.vue"),
        },
        {
          path:'/user/user-list/list',
          component: () => import("@/view/user/user_list.vue"),
        },
        {
          path:'/user/user-level/list',
          component: () => import("@/view/user/user-level.vue"),
        },
        {
          path:'/set/base/index',
          component: () => import("@/view/set/baseindex.vue"),
        },
        {
          path:'/set/express/index',
          component: () => import("@/view/set/expressindex.vue"),
        },
        {
          path:'/set/manager/index',
          component: () => import("@/view/set/managerindex.vue"),
        },
        {
          path:'/set/payment/index',
          component: () => import("@/view/set/paymentindex.vue"),
        },
        {
          path:'/shop/goods/create',
          component: () => import("@/view/shop_goods_list/shop_goods_create.vue"),

        }
      ],

    },
   
    {
      path: "/login",
      component: () => import("@/view/login/login.vue"),
    },
   
  ],
});
router.beforeEach(function(to,from,next){
  if(to.path=='/login'){return next()}
  const token=store.state.token
  if(token){
     return next()
  } else{
     return  router.push('/login') 
  }
})
export default router